import 'package:crm/components/ui/skip_down_time_progress.dart';
import 'package:crm/pages/index_page.dart';
import 'package:crm/routers/application.dart';
import 'package:crm/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class SplashScreenPage extends StatefulWidget {
  @override
  createState() => _SplashScreenPageState();
}

class _SplashScreenPageState extends State<SplashScreenPage> {
  /// 是否第一次打开APP
  bool firstOpen;

  // Hitokoto data;

  @override
  void initState() {
    super.initState();
    SchedulerBinding.instance.addPostFrameCallback((callback) {
      // 设置EasyRefresh的默认样式
      EasyRefresh.defaultHeader = ClassicalHeader(
          enableInfiniteRefresh: false,
          refreshText: '拉动刷新',
          refreshReadyText: '释放刷新',
          refreshingText: '正在刷新...',
          refreshedText: '刷新完成',
          refreshFailedText: '刷新失败',
          noMoreText: '没有更多数据',
          infoText: '更新于 %T');
      EasyRefresh.defaultFooter = ClassicalFooter(
          enableInfiniteLoad: true,
          loadText: '拉动加载',
          loadReadyText: '释放加载',
          loadingText:'加载中...',
          loadedText: '加载完成',
          loadFailedText: '加载失败',
          noMoreText: '没有更多数据',
          infoText: '更新于 %T');
    });
    // getHitokotoData();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334, allowFontScaling: true);

    return Stack(children: <Widget>[
      ConstrainedBox(
          constraints: BoxConstraints.expand(),
          child: Image.asset("images/splash.jpg", fit: BoxFit.cover)),
      Positioned(
          child: SkipDownTimeProgress(
              color: Colors.red,
              radius: 22.0,
              duration: Duration(seconds: 5),
              size: Size(25.0, 25.0),
              skipText: "跳过",
              onTap: () => Application.router.navigateTo(context, '/indexPage',replace: true),
              onFinishCallBack: (bool value) {
                if (value)
                  Navigator.of(context).pushAndRemoveUntil(
                      MaterialPageRoute(builder: (context) => IndexPage()),
                      (route) => route == null);
              }),
          top: Utils.topSafeHeight + 20,
          right: 30),
      Positioned(
          child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
            Container(
                padding: EdgeInsets.all(20),
                alignment: Alignment.centerLeft,
                width: double.infinity,
                child: Text('世界未亡,死不投降',
                    style: TextStyle(
                        color: Colors.redAccent,
                        fontSize: 16,
                        height: 2.0,
                        decoration: TextDecoration.none))),
            Container(
                padding: EdgeInsets.only(right: 20),
                alignment: Alignment.centerRight,
                width: double.infinity,
                child: Text('--张远涛',
                    style: TextStyle(
                        color: Colors.grey, fontSize: ScreenUtil().setSp(30))))
          ]),
          left: 0,
          right: 0,
          bottom: Utils.height / 2.2)
    ]);
  }

  // void goToHomePage(BuildContext context) async {
  //   firstOpen = SpUtil.getBool('first_open', defValue: true);

  //   debugPrint("$firstOpen");
  //   if (!firstOpen) {
  //     if (Store.value<UserModel>(context, listen: false).isLogin()) {
  //       pushAndRemovePage(context, HomePage());
  //     } else {
  //       pushAndRemovePage(context, LoginPage());
  //     }
  //   } else {
  //     SpUtil.setBool("first_open", false);
  //     pushAndRemovePage(context, IntroSlidePage());
  //   }
  // }

  // void getHitokotoData() async {
  //   data = await ApiService.hitokoto();
  //   if (mounted) {
  //     setState(() {});
  //   }
  // }
}
